"use strict";
cc._RF.push(module, '0a3b8UtZW9ILakuCwy6cERx', 'gameShareAdsVideo');
// Script/SdkTools/gameShareAdsVideo.ts

"use strict";
/**
 * 广告sdk & 网络控制
 * ts 版本
 * 单例
 */
Object.defineProperty(exports, "__esModule", { value: true });
var Define_1 = require("./Define");
var Utils_1 = require("./Utils");
var gameShareAdsVideo = /** @class */ (function () {
    function gameShareAdsVideo() {
        this.isdebug = true; //true 是测试模式  该模式 无广告 无 网络
        this.videoRecordingState = 0;
        this.video_recorder = null;
        this.videoStartTime = null;
        this.videoPath = null;
        this.videoIsExist = 0; //视频是否存在 默认存在
        this.recorderTime = 120; //视频录制时间
        this.videoAd = null; //激励视频
        this.chaPingErr = false; //插屏报错（触发频繁限制等）
        this.chaPing = null;
        this.bannerAd = null; //横屏广告
        this.videoCallBack = null; //激励视频成功回调
        this.videoFailCallBack = null; //激励视频失败回调
        this.isshowbanner = false;
        //platformSdk:any = tt //字节跳动sdk
        this.Ad_Custom_DanGe = null; //单个
        this.Ad_Custom_HengXiang = null; //横向
        this.Ad_Custom_ShuXiang_R = null; //竖向   靠右边
        this.Ad_Custom_ShuXiang_L = null; //竖向   靠左边
        this.Ad_Custom_JuZhen = null; //矩阵    
        this.wx_info = {
            gamename: "",
            shareTitle: '',
            appId: '',
            bannerId: "adunit-ae3a557d1b2fb2c4",
            videoId2: 'adunit-2f4056c40bc7abb4',
            chapingId: 'adunit-cb292b2f5571cafb',
            NativeAd: {
                juzhen: 'adunit-3fb31519568c00e7',
                heng4: 'adunit-5735928f6cb04468',
                zong4_R: "adunit-3bc1914fd8075d54",
                zong4_L: "adunit-9b733a09d32279f5",
            },
            templateId: ['', '', '', ''],
            videoTopics: ['', '']
        };
        this.tt_info = {
            gamename: "游戏名称",
            shareTitle: '#分享标题1#分享标题2',
            appId: 'ttf7f9814468c8a48702',
            videoId: 'omf0jln40ha4kd436c',
            chapingId: '30nfue6gfdi1jc60a9',
            bannerId: "a7fafbe768045fle10",
            templateId: ['', '', '', ''],
            videoTopics: ['找茬', '找不同'],
            appSecret: '',
        };
        this.url = '';
        this.web_url = '';
    }
    Object.defineProperty(gameShareAdsVideo, "Instance", {
        get: function () {
            if (null == this._instance) {
                this._instance = new gameShareAdsVideo();
            }
            return this._instance;
        },
        enumerable: false,
        configurable: true
    });
    Object.defineProperty(gameShareAdsVideo.prototype, "platform", {
        get: function () {
            if (cc.sys.platform == cc.sys.BYTEDANCE_GAME) {
                this._platform = 'tt';
                return this._platform;
            }
            else if (cc.sys.platform == cc.sys.WECHAT_GAME) {
                this._platform = 'wx';
                return this._platform;
            }
        },
        set: function (str) {
            this._platform = str;
        },
        enumerable: false,
        configurable: true
    });
    /**
     * 获取平台 类
     */
    gameShareAdsVideo.prototype.getPlatformClass = function () {
        var p_class = null;
        switch (this.platform) {
            case 'tt':
                //@ts-ignore
                p_class = tt;
                break;
            case 'wx':
                //@ts-ignore
                p_class = wx;
                break;
        }
        return p_class;
    };
    /**
     * 获取分享标题
     */
    gameShareAdsVideo.prototype.getShareTitle = function () {
        var title = '';
        switch (this.platform) {
            case 'tt':
                title = this.tt_info.shareTitle;
                break;
            case 'wx':
                title = this.wx_info.shareTitle;
                break;
        }
        return title;
    };
    /**
     * 获取名字
     */
    gameShareAdsVideo.prototype.getName = function () {
        var name = '';
        switch (this.platform) {
            case 'tt':
                name = this.tt_info.gamename;
                break;
            case 'wx':
                name = this.wx_info.gamename;
                break;
        }
        return name;
    };
    /**
     * 获取appid
     */
    gameShareAdsVideo.prototype.getAppId = function () {
        var appid = '';
        switch (this.platform) {
            case 'tt':
                appid = this.tt_info.appId;
                break;
            case 'wx':
                appid = this.wx_info.appId;
                break;
        }
        return appid;
    };
    /**
     * 获取AppSecret
     */
    gameShareAdsVideo.prototype.getAppSecret = function () {
        var appSecret = '';
        return appSecret;
    };
    /**
     * 获取bannerid
     */
    gameShareAdsVideo.prototype.getBannerId = function () {
        var bannerID = '';
        switch (this.platform) {
            case 'tt':
                bannerID = this.tt_info.bannerId;
                break;
            case 'wx':
                bannerID = this.wx_info.bannerId;
                break;
        }
        return bannerID;
    };
    /**
     * 获取videoid
     */
    gameShareAdsVideo.prototype.getVideoId = function () {
        var videoId = '';
        switch (this.platform) {
            case 'tt':
                videoId = this.tt_info.videoId;
                break;
            case 'wx':
                videoId = this.wx_info.videoId;
                break;
        }
        return videoId;
    };
    gameShareAdsVideo.prototype.getVideoId2 = function () {
        if (this.platform == 'wx') {
            var videoId = '';
            videoId = this.wx_info.videoId2;
            return videoId;
        }
    };
    /**
     * 获取id
     * @param {*012} type
     */
    gameShareAdsVideo.prototype.getNativeAd = function (type) {
        var id = '';
        switch (this.platform) {
            case 'wx':
                if (type == Define_1.CustomAdType.More) {
                    id = this.wx_info.NativeAd.juzhen;
                }
                else if (type == 1) {
                    id = this.wx_info.NativeAd.heng4;
                }
                else if (type == 2) {
                }
                break;
        }
        return id;
    };
    /**
     * 获取插屏广告id
     */
    gameShareAdsVideo.prototype.getChaPingId = function () {
        var chapingId = '';
        switch (this.platform) {
            case 'tt':
                chapingId = this.tt_info.chapingId;
                break;
            case 'wx':
                chapingId = this.wx_info.chapingId;
                break;
        }
        return chapingId;
    };
    /**
     * 获取分享审核id
     */
    gameShareAdsVideo.prototype.getTemplateId = function () {
        var templateId = '';
        return templateId;
    };
    /**
     * 游戏分享
     */
    gameShareAdsVideo.prototype.game_share = function (callBack) {
        console.log('游戏分享');
        if (cc.sys.platform === cc.sys.WECHAT_GAME) {
            //console.log('游戏分享')
            this.getPlatformClass().shareAppMessage({
                // templateId: templateId, // 替换成通过审核的分享ID
                // query: "",
                title: '80%老同学都卡在这里了，难道这关就这么难了吗？',
                imageUrlId: 'vB2VxuHaRdqIQxGytKrYXw==',
                imageUrl: 'https://mmocgame.qpic.cn/wechatgame/fIiaXSY0ANicTRfDr395BbEDT0R54yO9lsUWiasL5Xg8XIcrwUOvqOA0vt6hMOp29tu/0',
                success: function () {
                    //console.log("分享成功");
                    callBack();
                },
                fail: function (e) {
                    //console.log("分享失败");
                }
            });
        }
        else if (cc.sys.platform == cc.sys.BYTEDANCE_GAME_SUB) {
            if (this.isdebug)
                return callBack();
            //console.log('游戏分享')
            var title = this.getShareTitle();
            var templateId = this.getTemplateId();
            this.getPlatformClass().shareAppMessage({
                templateId: templateId,
                query: "",
                success: function () {
                    //console.log("分享成功");
                    callBack();
                },
                fail: function (e) {
                    //console.log("分享失败");
                }
            });
        }
    };
    /**
     * 分享到好友
     * @param callback
     */
    gameShareAdsVideo.prototype.shareGameToFriend = function (callback, note) {
        console.log('分享到好友');
        if (this.isdebug)
            return callback();
        var notestr = '你的好友邀请你一起战斗';
        if (note)
            notestr = note;
        var self = this;
        if (cc.sys.platform === cc.sys.WECHAT_GAME) {
            var title = this.getName();
            this.getPlatformClass().shareAppMessage({
                channel: "invite",
                title: title,
                desc: notestr,
                imageUrl: "",
                query: "",
                success: function () {
                    //console.log("分享成功");
                },
                fail: function (e) {
                    //console.log("分享失败");
                },
            });
        }
        else if (cc.sys.platform == cc.sys.BYTEDANCE_GAME) {
            if (this.isdebug)
                return callback();
            var title = this.getName();
            this.getPlatformClass().shareAppMessage({
                channel: "invite",
                title: title,
                desc: notestr,
                imageUrl: "",
                query: "",
                success: function () {
                    //console.log("分享成功");
                },
                fail: function (e) {
                    //console.log("分享失败");
                },
            });
        }
    };
    /**
     *  banner 广告显示
     */
    gameShareAdsVideo.prototype.bannerAds_Show = function () {
        console.log('banner 广告显示');
        if (this.isdebug)
            return;
        var self = this;
        if (cc.sys.platform == cc.sys.BYTEDANCE_GAME) {
            if (self.bannerAd == null) {
                var winSize_1 = this.getPlatformClass().getSystemInfoSync();
                var bannerWidth = winSize_1.windowWidth;
                var bannerHeight = 100;
                // // 广告
                var bannerID = this.getBannerId();
                self.bannerAd = this.getPlatformClass().createBannerAd({
                    adUnitId: bannerID,
                    style: {
                        left: (winSize_1.windowWidth - bannerWidth) / 2,
                        top: winSize_1.windowHeight - bannerHeight,
                        width: bannerWidth,
                        height: bannerHeight,
                    }
                });
                self.bannerAd.onResize(function (res) {
                    self.bannerAd.style.left = (winSize_1.windowWidth - res.width) / 2;
                    self.bannerAd.style.top = winSize_1.windowHeight - res.height;
                });
                self.bannerAd.onError(function (res) {
                    console.log(res);
                });
            }
            if (self.bannerAd != null) {
                console.log('显示banner');
                self.bannerAd.show();
            }
        }
        else if (cc.sys.platform === cc.sys.WECHAT_GAME) {
            if (self.bannerAd == null) {
                self.isshowbanner = false;
                var winSize_2 = this.getPlatformClass().getSystemInfoSync();
                var bannerWidth = winSize_2.windowWidth;
                var bannerHeight = 100;
                // // 广告
                var bannerID = this.getBannerId();
                self.bannerAd = this.getPlatformClass().createBannerAd({
                    adUnitId: bannerID,
                    adIntervals: 30,
                    style: {
                        left: (winSize_2.windowWidth - bannerWidth) / 2,
                        top: winSize_2.windowHeight - bannerHeight,
                        width: bannerWidth,
                        height: bannerHeight,
                    }
                });
                self.bannerAd.onResize(function (res) {
                    self.bannerAd.style.left = (winSize_2.windowWidth - res.width) / 2;
                    self.bannerAd.style.top = winSize_2.windowHeight - res.height;
                });
                self.bannerAd.onError(function (res) {
                    console.log('banner失败', res);
                    self.bannerAd = null;
                    //self.bannerAds_Load()
                });
                self.bannerAd.onLoad(function () {
                    console.log('banner 广告加载成功');
                    //gameConfig.isshowbanner = true
                });
            }
            if (self.bannerAd != null) {
                self.bannerAd.show();
            }
        }
    };
    /**
     * banner 广告隐藏
     */
    gameShareAdsVideo.prototype.bannerAds_Hide = function () {
        console.log('banner 广告隐藏');
        if (this.isdebug)
            return;
        var self = this;
        if (cc.sys.platform === cc.sys.WECHAT_GAME) {
            if (self.bannerAd != null) {
                self.bannerAd.hide();
            }
        }
        else if (cc.sys.platform == cc.sys.BYTEDANCE_GAME) {
            if (self.bannerAd != null) {
                self.bannerAd.hide();
            }
        }
    };
    /**
     * 插屏广告加载
     */
    gameShareAdsVideo.prototype.chaPingAds_Load = function () {
        console.log('插屏广告加载');
        if (this.isdebug)
            return;
        if (cc.sys.platform == cc.sys.WECHAT_GAME) {
            var chapingId = this.getChaPingId();
            this.chaPing = this.getPlatformClass().createInterstitialAd({ adUnitId: chapingId });
            this.chaPing.onError(function (err) {
                console.log('插屏广告拉取失败', err);
                //gameConfig.chaPing = wx.createInterstitialAd({ adUnitId: chapingId })
            });
        }
    };
    /**
     * 插屏广告显示
     */
    gameShareAdsVideo.prototype.chaPingAds_Show = function (callback) {
        console.log('插屏广告显示');
        if (this.isdebug)
            return;
        var self = this;
        if (cc.sys.platform == cc.sys.WECHAT_GAME) {
            if (self.chaPingErr == true) {
                if (callback) {
                    //this.showToast('资源未准备好...')
                    console.log('资源未准备好...');
                    return callback();
                }
            }
            self.chaPingErr = true;
            setTimeout(function () {
                self.chaPingErr = false;
            }, 45000);
            self.chaPing.show()
                .then(function () {
                if (callback) {
                    callback();
                }
            })
                .catch(function (err) {
                console.error(err);
                //self.showToast('资源未准备好...')
                console.log('展示广告失败');
                if (callback) {
                    callback();
                }
                //gameConfig.chaPing = wx.createInterstitialAd({ adUnitId: this.getChaPingId() })
            });
        }
        else if (cc.sys.platform == cc.sys.BYTEDANCE_GAME) {
            var sysData = this.getPlatformClass().getSystemInfoSync();
            if (sysData.appName == 'devtools')
                return console.log('插屏开发工具不操作');
            if (self.chaPingErr == true)
                return;
            self.chaPingErr = true;
            setTimeout(function () {
                self.chaPingErr = false;
            }, 60000);
            var chapingId = this.getChaPingId();
            if (this.getPlatformClass().createInterstitialAd) {
                var interstitialAd_1 = this.getPlatformClass().createInterstitialAd({
                    adUnitId: chapingId
                });
                interstitialAd_1
                    .load()
                    .then(function () {
                    interstitialAd_1.show();
                })
                    .catch(function (err) {
                    console.log(err);
                    setTimeout(function () {
                        interstitialAd_1.load().then(function () { interstitialAd_1.show; });
                    }, 5);
                });
                interstitialAd_1.onClose(function () {
                    if (interstitialAd_1) {
                        interstitialAd_1.destroy();
                    }
                });
            }
        }
    };
    /**
     * 创建原生广告模板
     * @param {0:单个，1：横向多个，2：竖向多个，3：矩阵} type
     */
    gameShareAdsVideo.prototype.createCustomAd = function (type) {
        if (cc.sys.platform == cc.sys.WECHAT_GAME) { //微信
            console.log('创建原生广告type=', type);
            var inifo = this.getPlatformClass().getSystemInfoSync();
            if (Utils_1.default.compareVersion(inifo.SDKVersion, '2.11.1') >= 0) {
                if (type == Define_1.CustomAdType.One) { //单个
                    //常规样式默认画布为 60×104 像素
                    //卡片样式默认画布为 68×106 像素
                }
                else if (type == Define_1.CustomAdType.Heng) { //横向 顶部 水平布局默认画布为 360×106 像素
                    var adWidth = 360;
                    var adHeight = 110;
                    var id = this.getNativeAd(type);
                    this.Ad_Custom_HengXiang = this.getPlatformClass().createCustomAd({
                        adUnitId: id,
                        adIntervals: 35,
                        style: {
                            left: (inifo.screenWidth - adWidth) / 2,
                            top: inifo.screenHeight - adHeight,
                            fixed: false
                        }
                    });
                    this.Ad_Custom_HengXiang.onLoad(function (res) {
                        console.log('横向原生广告加载', res);
                    });
                    this.Ad_Custom_HengXiang.onError(function (res) {
                        console.log('横向原生广告报错', res);
                    });
                    this.Ad_Custom_HengXiang.onHide(function (res) {
                        console.log('横向原生监听关闭');
                    });
                }
                else if (type == Define_1.CustomAdType.Shu) { //竖向 左右 垂直布局默认画布为 72×410 像素
                    var adWidth = 72;
                    var adHeight = 410;
                    var id_r = this.wx_info.NativeAd.zong4_R;
                    this.Ad_Custom_ShuXiang_R = this.getPlatformClass().createCustomAd({
                        adUnitId: id_r,
                        adIntervals: 35,
                        style: {
                            left: (inifo.screenWidth - adWidth),
                            top: inifo.screenHeight - adHeight,
                            fixed: false
                        }
                    });
                    var id_L = this.wx_info.NativeAd.zong4_L;
                    this.Ad_Custom_ShuXiang_L = this.getPlatformClass().createCustomAd({
                        adUnitId: id_L,
                        adIntervals: 35,
                        style: {
                            left: 0,
                            top: inifo.screenHeight - adHeight,
                            fixed: false
                        }
                    });
                }
                else if (type == Define_1.CustomAdType.More) { //矩阵
                    // 2×5 布局默认画布为 360×188 像素
                    // 5×5 布局默认画布为 360×352 像素  
                    var adWidth = 360;
                    var adHeight = 500;
                    var id = this.getNativeAd(type);
                    this.Ad_Custom_JuZhen = this.getPlatformClass().createCustomAd({
                        adUnitId: id,
                        adIntervals: 35,
                        style: {
                            left: (inifo.screenWidth - adWidth) / 2,
                            top: (inifo.screenHeight - adHeight) / 2,
                            fixed: false
                        }
                    });
                    this.Ad_Custom_JuZhen.onLoad(function (res) {
                        //console.log('矩阵原生广告加载', res)
                    });
                    this.Ad_Custom_JuZhen.onError(function (res) {
                        //console.log('矩阵原生广告报错', res)
                    });
                    this.Ad_Custom_JuZhen.onHide(function (res) {
                        //console.log('矩阵原生监听关闭')
                    });
                }
            }
        }
    };
    /**
     * 展示
     * @param {*} ad
     */
    gameShareAdsVideo.prototype.showCustomAd = function (type) {
        if (cc.sys.platform == cc.sys.WECHAT_GAME) { //微信
            console.log('展示原生广告', type);
            switch (type) {
                case 0:
                    break;
                case Define_1.CustomAdType.Heng:
                    this.Ad_Custom_HengXiang.show();
                    break;
                case Define_1.CustomAdType.Shu:
                    this.Ad_Custom_ShuXiang_R.show();
                    this.Ad_Custom_ShuXiang_L.show();
                    break;
                case Define_1.CustomAdType.More:
                    this.Ad_Custom_JuZhen.show();
                    break;
            }
        }
    };
    /**
     * 隐藏, 销毁原生广告模板
     */
    gameShareAdsVideo.prototype.hideCustomAd = function (type) {
        if (cc.sys.platform == cc.sys.WECHAT_GAME) { //微信
            console.log('关闭原生广告', type);
            switch (type) {
                case 0:
                    break;
                case Define_1.CustomAdType.Heng:
                    this.Ad_Custom_HengXiang.hide();
                    break;
                case Define_1.CustomAdType.Shu:
                    this.Ad_Custom_ShuXiang_R.hide();
                    this.Ad_Custom_ShuXiang_L.hide();
                    break;
                case Define_1.CustomAdType.More:
                    this.Ad_Custom_JuZhen.hide();
                    break;
            }
        }
    };
    /**
     * 激励广告加载
     */
    gameShareAdsVideo.prototype.motivational_Video_Load = function () {
        console.log('激励广告加载');
        if (this.isdebug)
            return;
        if (cc.sys.platform == cc.sys.WECHAT_GAME) {
            var self = this;
            var videoId = this.getVideoId2();
            self.videoAd = this.getPlatformClass().createRewardedVideoAd({
                adUnitId: videoId,
            });
            self.videoAd.onError(function (res) {
                console.log('激励视频错误', res);
            });
            self.videoAd.load();
            var endCallBack = function (res) {
                if (res.isEnded == true) {
                    if (self.videoCallBack != null) {
                        console.log('获取奖励');
                        self.videoCallBack();
                    }
                    if (this._type != -1) {
                        self.showToast('已获得');
                    }
                }
                else {
                    if (self.videoFailCallBack != null)
                        self.videoFailCallBack();
                }
                self.isvideoend = true;
                setTimeout(function () {
                    self.checkVideo = false;
                }, 60000);
            };
            self.videoAd.onClose(endCallBack); //绑定结束回调
        }
        else if (cc.sys.platform == cc.sys.BYTEDANCE_GAME) {
            var sysData = this.getPlatformClass().getSystemInfoSync();
            if (sysData.appName == 'devtools')
                return console.log('开发工具不操作');
            var self = this;
            var videoId = this.getVideoId();
            this.videoAd = this.getPlatformClass().createRewardedVideoAd({
                adUnitId: videoId,
            });
            this.videoAd.onError(function (res) {
                //console.log('激励视频错误',res)
            });
            this.videoAd.load();
            var endCallBack = function (res) {
                if (res.isEnded == true) {
                    if (self.videoCallBack != null) {
                        //console.log('获取奖励')
                        self.videoCallBack();
                    }
                    if (this._type != -1) {
                        self.showToast('已获得');
                    }
                }
                else {
                    if (self.videoFailCallBack != null)
                        self.videoFailCallBack();
                }
                self.isvideoend = true;
            };
            self.videoAd.onClose(endCallBack); //绑定结束回调
        }
    };
    /**
     * 展示激励视频
     * 参数1 成功回调
     * 参数2 失败回调 可以省略
     */
    gameShareAdsVideo.prototype.motivational_Video_Show = function (success, faile, type) {
        console.log('展示激励视频');
        if (this.isdebug)
            return success();
        var self = this;
        if (this.checkVideo == true)
            return this.showToast('勿频繁点击');
        setTimeout(function () {
            self.checkVideo = false;
        }, 1000);
        this.videoCallBack = success;
        this.videoFailCallBack = faile;
        this._type = type;
        if (cc.sys.platform == cc.sys.WECHAT_GAME) { //微信
            this._type = type;
            if (self.videoAd == null || self.videoAd == undefined) {
                return this.videoCallBack();
            }
            self.videoAd.onError(function (res) {
                console.log('广告出错监听', res);
            });
            // /**展示 */
            self.videoAd
                .show()
                .then(function () {
            })
                .catch(function (err) {
                self.showToast('激励视频播放失败');
                console.log('打印激励视频错误', err);
                // 可以手动加载一次
                self.videoAd.load().then(function () {
                    // 加载成功后需要再显示广告
                    return self.videoAd.show();
                });
            });
        }
        else if (cc.sys.platform == cc.sys.BYTEDANCE_GAME) {
            this.checkVideo = true;
            var sysData = this.getPlatformClass().getSystemInfoSync();
            if (sysData.appName == 'devtools')
                return success(), console.log('开发工具不操作');
            if (this.videoAd == null || this.videoAd == undefined) {
                return this.videoCallBack();
            }
            this.videoAd.onError(function (res) {
                //console.log('广告出错监听', res)
            });
            // /**展示 */
            this.videoAd
                .show()
                .then(function () {
            })
                .catch(function (err) {
                self.showToast('激励视频播放失败');
                //console.log('打印激励视频错误', err)
                // 可以手动加载一次
                self.videoAd.load().then(function () {
                    // 加载成功后需要再显示广告
                    return self.videoAd.show();
                });
            });
        }
        else {
            self.videoCallBack();
        }
    };
    /**
     * 录制视频开始
     */
    gameShareAdsVideo.prototype.recording_Video_Start = function () {
        console.log('录制视频开始');
        if (this.isdebug)
            return;
        var self = this;
        if (cc.sys.platform == cc.sys.BYTEDANCE_GAME) {
            var sysData = this.getPlatformClass().getSystemInfoSync();
            if (sysData.appName == 'devtools')
                return console.log('开发工具不操作');
            self.videoRecordingState = 1;
            self.videoIsExist = 0;
            self.video_recorder = this.getPlatformClass().getGameRecorderManager();
            self.videoStartTime = Date.parse(new Date().toString()); //Date.parse(new Date());
            //开始回调
            self.video_recorder.onStart(function (res) {
                //console.log('录屏开始');
                //console.log(res);
            });
            //开始
            self.video_recorder.start({
                duration: self.recorderTime,
            });
            //录制结束回调
            self.video_recorder.onStop(function (res) {
                self.videoRecordingState = 2;
                self.videoPath = res.videoPath;
                //console.log('录屏结束', self.videoPath)
                // do somethine;
            });
            //录制错误回调
            self.video_recorder.onError(function (res) {
                //console.log("录屏error", res)
            });
        }
    };
    /**
     * 录制视频结束
     */
    gameShareAdsVideo.prototype.recording_Video_End = function () {
        console.log('录制视频结束');
        if (this.isdebug)
            return;
        if (cc.sys.platform == cc.sys.BYTEDANCE_GAME) {
            var sysData = this.getPlatformClass().getSystemInfoSync();
            if (sysData.appName == 'devtools')
                return console.log('开发工具不操作');
            var self = this;
            //console.log('录屏结束');
            //gameConfig.shareVideoTips = 0;
            if (self.video_recorder) {
                var endTime = Date.parse(new Date().toString()); //Date.parse(new Date());
                if ((endTime - self.videoStartTime) / 1000 <= 5) {
                    self.videoIsExist = 1;
                }
                else {
                    self.videoIsExist = 0;
                }
                self.video_recorder.stop();
            }
        }
    };
    /**
     * 录制视频分享
     * 参数1 成功回调方法
     * 参数2 失败回调方法
     */
    gameShareAdsVideo.prototype.recording_Video_Share = function (callBack, failCallBack) {
        console.log('录制视频分享');
        if (cc.sys.platform == cc.sys.WECHAT_GAME) {
            this.game_share(function () { });
            callBack();
        }
        else if (cc.sys.platform == cc.sys.BYTEDANCE_GAME) {
            if (this.isdebug)
                return callBack();
            var sysData = this.getPlatformClass().getSystemInfoSync();
            if (sysData.appName == 'devtools')
                return console.log('开发工具不操作');
            var self = this;
            if (self.videoIsExist == 1) {
                self.showToast('录制时间过短');
                return;
            }
            var result = 200;
            self.videoRecordingState = 3;
            this.getPlatformClass().shareAppMessage({
                channel: 'video',
                title: '',
                imageUrl: '',
                query: '',
                extra: {
                    videoPath: self.videoPath,
                    videoTopics: self.tt_info.videoTopics,
                    createChallenge: true
                },
                success: function () {
                    self.showToast('分享视频成功');
                    callBack();
                    //self.recording_Video_Start()
                },
                fail: function (e) {
                    result = 201;
                    self.showToast('分享视频失败');
                    //console.log('分享失败', e)
                    failCallBack();
                    //self.recording_Video_Start()
                }
            });
        }
        else {
            callBack();
        }
    };
    //录屏是否存在
    gameShareAdsVideo.prototype.getVideoIsExist = function () {
        return this.videoIsExist;
    };
    /**
     * 添加桌面
     * @param scb
     * @param fcb
     */
    gameShareAdsVideo.prototype.addShortcut = function (scb, fcb) {
        if (this.isdebug)
            return scb();
        this.getPlatformClass().addShortcut({
            success: function () {
                this.showToast("添加桌面成功");
                scb();
            },
            fail: function (err) {
                this.showToast("添加桌面失败");
                fcb();
            },
        });
    };
    /**
     * 检测是否添加到桌面
     * @returns true 不支持 或者 已添加
     */
    gameShareAdsVideo.prototype.checkShortcut = function () {
        if (this.isdebug)
            return;
        if ((cc.sys.platform == cc.sys.WECHAT_GAME || cc.sys.platform == cc.sys.BYTEDANCE_GAME) && cc.sys.os == cc.sys.OS_ANDROID) {
            var version = this.getPlatformClass().getSystemInfoSync().SDKVersion;
            if (Utils_1.default.compareVersion(version, '2.46.0') >= 0) {
                this.getPlatformClass().checkShortcut({
                    success: function (res) {
                        var exist = res.status.exist;
                        //console.log("检查快捷方式", res.status);
                        return exist;
                    },
                    fail: function (res) {
                        return true;
                        //console.log("检查快捷方式失败", res.errMsg);
                    },
                });
            }
            else {
                return true;
            }
        }
        else {
            return true;
        }
    };
    /**
     * 提示框
     */
    gameShareAdsVideo.prototype.showToast = function (str) {
        if (cc.sys.platform === cc.sys.WECHAT_GAME) {
            this.getPlatformClass().showToast({
                title: str,
                duration: 1000,
                success: function (res) {
                    //console.log(`${res}`);
                },
                fail: function (res) {
                    //console.log(`showToast调用失败`);
                }
            });
        }
        else {
            console.log(str);
        }
    };
    /**
     * 获取不重复的随机数
     * @param minValue 最小值
     * @param maxValue 最大值
     * @param valueNum 随机个数
     */
    gameShareAdsVideo.prototype.getRandomValueDif = function (minValue, maxValue, valueNum) {
        // 全部随机数值  
        var allNums = new Array;
        // 判断获取随机数个数  
        var size = valueNum ? (valueNum > maxValue - minValue + 1 ? maxValue - minValue + 1 : valueNum) : 1;
        // 生成随机数值区间数组  
        for (var i = minValue, k = 0; i <= maxValue; i++, k++) {
            allNums[k] = i;
        }
        var arr = [];
        // 随机从数组里面取值
        allNums.sort(function () { return 0.5 - Math.random(); });
        for (var j = 0; j < size; j++) {
            var index = Math.floor(Math.random() * allNums.length);
            arr.push(allNums[index]);
            var tmp = allNums[index];
            allNums[index] = allNums[allNums.length - 1];
            allNums[allNums.length - 1] = tmp;
            allNums.pop();
        }
        return arr;
    };
    /**
     * 获取范围内的随机数
     * @param minValue 最小值
     * @param maxValue 最大值
     */
    gameShareAdsVideo.prototype.getRangeRandom = function (minValue, maxValue) {
        // 获取数组从第一个开始到指定个数的下标区间  
        return this.getRandomValueDif(minValue, maxValue, 1)[0];
    };
    gameShareAdsVideo.prototype.vibrateShort = function () {
        if (cc.sys.platform == cc.sys.WECHAT_GAME || cc.sys.platform == cc.sys.BYTEDANCE_GAME) {
            this.getPlatformClass().vibrateShort();
        }
    };
    /**
     * 设置 抖音排行榜  数字类型排行榜
     * @param value     数值
     */
    gameShareAdsVideo.prototype.setImRankData_Num = function (value) {
        if (this.isdebug)
            return;
        if (cc.sys.platform == cc.sys.BYTEDANCE_GAME) {
            //@ts-ignore
            var sysinfo = tt.getSystemInfoSync();
            var sdkversion = sysinfo.SDKVersion;
            var appname = sysinfo.appName;
            var appVersion = sysinfo.version;
            if (Utils_1.default.compareVersion(sdkversion, '2.70.0') >= 0
                && (appname == 'Douyin' || appname == 'douyin_lite')
                && Utils_1.default.compareVersion(appVersion, '23.2.0') >= 0) {
                //@ts-ignore
                tt.setImRankData({
                    dataType: 0,
                    value: "" + value,
                    priority: 0,
                    extra: "extra",
                    success: function (res) {
                        console.log("setImRankData success res: " + res);
                    },
                    fail: function (res) {
                        console.log("setImRankData fail res: " + res.errMsg);
                    },
                });
            }
        }
    };
    /**
     * 获取数字类型原生排行榜
     */
    gameShareAdsVideo.prototype.getImRankList_Num = function () {
        if (this.isdebug)
            return;
        if (cc.sys.platform == cc.sys.BYTEDANCE_GAME) {
            //@ts-ignore
            var sysinfo = tt.getSystemInfoSync();
            var sdkversion = sysinfo.SDKVersion;
            var appname = sysinfo.appName;
            var appVersion = sysinfo.version;
            if (Utils_1.default.compareVersion(sdkversion, '2.70.0') >= 0
                && (appname == 'Douyin' || appname == 'douyin_lite')
                && Utils_1.default.compareVersion(appVersion, '23.2.0') >= 0) {
                //@ts-ignore
                tt.getImRankList({
                    relationType: "default",
                    dataType: 0,
                    rankType: "day",
                    suffix: "关",
                    rankTitle: "游戏排行榜",
                    success: function (res) {
                        console.log("getImRankData success res: " + res);
                    },
                    fail: function (res) {
                        console.log("getImRankData fail res: " + res.errMsg);
                    },
                });
            }
            else {
                this.showToast('app版本不支持该功能');
            }
        }
    };
    /**
     * 设置 抖音排行榜  枚举类型排行榜
     * @param value     数值
     * @param priority  权重
     */
    gameShareAdsVideo.prototype.setImRankData_Enum = function (value, priority) {
        if (this.isdebug)
            return;
        if (cc.sys.platform == cc.sys.BYTEDANCE_GAME) {
            //@ts-ignore
            var sysinfo = tt.getSystemInfoSync();
            var sdkversion = sysinfo.SDKVersion;
            var appname = sysinfo.appName;
            var appVersion = sysinfo.version;
            if (Utils_1.default.compareVersion(sdkversion, '2.70.0') >= 0
                && (appname == 'Douyin' || appname == 'douyin_lite')
                && Utils_1.default.compareVersion(appVersion, '23.2.0') >= 0) {
                //@ts-ignore
                tt.setImRankData({
                    dataType: 1,
                    value: "" + value,
                    priority: priority,
                    extra: "extra",
                    success: function (res) {
                        console.log("setImRankData success res: " + res);
                    },
                    fail: function (res) {
                        console.log("setImRankData fail res: " + res.errMsg);
                    },
                });
            }
        }
    };
    /**
     * 获取枚举类型原生排行榜
     */
    gameShareAdsVideo.prototype.getImRankList_Enum = function () {
        if (this.isdebug)
            return;
        if (cc.sys.platform == cc.sys.BYTEDANCE_GAME) {
            //@ts-ignore
            var sysinfo = tt.getSystemInfoSync();
            var sdkversion = sysinfo.SDKVersion;
            var appname = sysinfo.appName;
            var appVersion = sysinfo.version;
            if (Utils_1.default.compareVersion(sdkversion, '2.70.0') >= 0
                && (appname == 'Douyin' || appname == 'douyin_lite')
                && Utils_1.default.compareVersion(appVersion, '23.2.0') >= 0) {
                //@ts-ignore
                tt.getImRankList({
                    relationType: "default",
                    dataType: 1,
                    rankType: "day",
                    suffix: "",
                    rankTitle: "游戏排行榜",
                    success: function (res) {
                        console.log("getImRankData success res: " + res);
                    },
                    fail: function (res) {
                        console.log("getImRankData fail res: " + res.errMsg);
                    },
                });
            }
            else {
                this.showToast('app版本不支持该功能');
            }
        }
    };
    /**
     * 上传微信 游戏得分
     */
    gameShareAdsVideo.prototype.upWxHighScore = function (score, callBack) {
        if (cc.sys.platform == cc.sys.WECHAT_GAME) {
            //@ts-ignore
            wx.setUserCloudStorage({
                KVDataList: [{ key: 'checkout', value: String(score) }],
                success: function (res) {
                    console.log('上传排行数据success', res);
                    // // 让子域更新当前用户的最高分，因为主域无法得到getUserCloadStorage;
                    // let openDataContext = wx.getOpenDataContext();
                    // openDataContext.postMessage({
                    //     type: 'updateMaxScore',
                    // });
                    callBack();
                },
                fail: function (res) {
                    console.log('上传排行数据fail', res);
                }
            });
        }
    };
    gameShareAdsVideo._instance = null;
    return gameShareAdsVideo;
}());
exports.default = gameShareAdsVideo;

cc._RF.pop();